import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: zm
 * Date: 2023/5/26
 */
public class Demo43 {
    static int N = 2010,n,m = 1000000007;
    static int[][] c = new int[N][N];

    public static void init() {
        for (int i = 0; i < N; i++)
            for (int j = 0; j <= i ; j++)
                if(j == 0)c[i][j] = 1;
        else c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m;
    }
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        init();
        while(n -- > 0){
            int a = scan.nextInt();
            int b = scan.nextInt();
            System.out.println(c[a][b]);
        }
    }
}
